#ifndef __LOADER_H__
#define __LOADER_H__

#include "hi_type.h"

#define BOOT_MAGIC_SIZE               8
#define BOOT_NAME_SIZE                16
#define BOOT_ARGS_SIZE                512


#define KEY_MENU                      3
#define KEY_OK                        5

//partition name define
#define FASTBOOT                       "boot"
#define BOOTARGS                       "bootargs"
#define BOOTARGSBAK                    "bootargsbak"
#define STBID                          "stbid"
#define LOADERDB                       "loaderdb"
#define LOADERDBBAK                    "loaderdbbak"
#define LOADER                         "loader"
#define LOADERBAK                      "loaderbak"
#define KERNEL                         "kernel"
#define ROOTFS                         "rootfs"
#define FASTPLAY                       "fastplay"

/*LOADER magic number of OTA parameters. it is used as a flag of data verification.*/
#define LOADER_MAGIC_NUMBER            0x4C4F4144

#define UIH_NMLEN		               32

/*Define kernel image head.*/
typedef struct uImage_header {
	HI_U32	ih_magic;	/* Image Header Magic Number	*/
	HI_U32	ih_hcrc;	/* Image Header CRC Checksum	*/
	HI_U32	ih_time;	/* Image Creation Timestamp	*/
	HI_U32	ih_size;	/* Image Data Size		*/
	HI_U32	ih_load;	/* Data	 Load  Address		*/
	HI_U32	ih_ep;		/* Entry Point Address		*/
	HI_U32	ih_dcrc;	/* Image Data CRC Checksum	*/
	HI_U8		ih_os;		/* Operating System		*/
	HI_U8		ih_arch;	/* CPU architecture		*/
	HI_U8		ih_type;	/* Image Type			*/
	HI_U8		ih_comp;	/* Compression Type		*/
	HI_U8		ih_name[UIH_NMLEN];	/* Image Name		*/
} uImage_header_t;

/*Define parameter head.*/
typedef struct tagParaHead
{
    HI_U32   u32MagicNumber;     /*Magic number name */
    HI_U32   u32Crc;             /*CRC verification value */
    HI_U32   u32Length;          /*length of upgrade parameter.*/
}UPGRD_PARA_HEAD_S;

/*Define upgrade tag parameter.*/
typedef struct tagLoaderUpgrdTagParam
{
    HI_BOOL           bTagNeedUpgrd;    /*  whether normal upgrade.*/
    HI_BOOL           bTagManuForceUpgrd;   /*  whether force upgrade.*/
}UPGRD_TAG_PARA_S;

#ifdef CONFIG_SUPPORT_CA_RELEASE
    #define LOADER_PROMPT(fmt...)
    #define LOADER_ASSERT(fmt...) 
#else

    #ifdef LOADER_DBG
        #define LOADER_PROMPT(fmt...)   printf(fmt)
    #else
        #define LOADER_PROMPT(fmt...)
    #endif

#define LOADER_ASSERT(fmt...)      \
        do{                            \
           printf("ASSERT:[%s %d]", __FUNCTION__, __LINE__);  \
           printf(fmt);                 \
           printf("\n");                \
          }while(0)

#endif
/***************************************************************************/
HI_S32 Loader_Main(HI_VOID);
HI_U32 Loader_ReadUpgrdTag(UPGRD_TAG_PARA_S *pstTagParam);
HI_U32 Loader_WriteUpgrdTag(UPGRD_TAG_PARA_S *pstTagParam);
HI_S32 Loader_CheckManuForceUpgrade(HI_VOID);

#endif
